package com.gviiii.baiduai.util;

import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;

public class DateUtil {

    public static LocalDateTime createDateTimeByInstant(Instant instant){
        return LocalDateTime.ofInstant(instant, ZoneId.systemDefault());
    }

    public static String formatDateTime(LocalDateTime localDateTime,String pattern){
        return localDateTime.format(DateTimeFormatter.ofPattern(pattern));
    }

    public static long dissimilarityBySecond(LocalDateTime newDateTime,LocalDateTime oldDateTime){
        return newDateTime.toEpochSecond(ZoneOffset.of("+8"))-oldDateTime.toEpochSecond(ZoneOffset.of("+8"));
    }

    public static long dissimilarityByHours(LocalDateTime newDateTime,LocalDateTime oldDateTime){
        return dissimilarityBySecond(newDateTime,oldDateTime)/3600;
    }

    public static long dissimilarityByMinutes(LocalDateTime newDateTime,LocalDateTime oldDateTime){
        return dissimilarityBySecond(newDateTime,oldDateTime)/60;
    }
}
